package server

import (
	"github.com/google/uuid"
	"os"
	"syscall"
	"time"
	"wmicro/registry"
)

type IServer interface {
	Run() error
}

type Option struct {
	ID                    string                        // 服务唯一id
	Name                  string                        // 服务名称
	Post                  int                           // 8090
	Timeout               time.Duration                 // 超时时间
	Signals               []os.Signal                   // 监听服务退出
	ServiceRegisterCenter registry.IRegistrar           // 服务注册中心
	ServiceRegisterInfo   *registry.ServiceRegisterInfo // 服务注册信息
	ServiceRegisterHost   string                        // 服务注册到注册中心的地址 “192.168.0.1”
}

func NewDefault() (*Option, error) {
	uid, err := uuid.NewUUID()
	if err != nil {
		return nil, err
	}
	return &Option{
		ID:                  uid.String(),
		Post:                2345,
		Signals:             []os.Signal{syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGINT},
		Timeout:             time.Second * 30, // 30 秒
		ServiceRegisterHost: "127.0.0.1",
	}, nil
}

func NewHttpDefault() (*Option, error) {
	o, err := NewDefault()
	o.Post = 3939
	return o, err
}
